#!/usr/bin/env python3
"""
一键启动前后端服务 - 最简版本
"""

import subprocess
import sys
import time
from pathlib import Path

def main():
    print("🚀 启动心理健康聊天机器人...")
    
    # 获取项目根目录
    root_dir = Path(__file__).parent
    backend_dir = root_dir / "server" / "mvp-llm-app-scaffold"
    frontend_dir = root_dir / "frontend"
    
    try:
        # 启动后端 (agent-py311环境)
        print("📡 启动后端服务 (端口8002)...")
        backend_cmd = f'start "后端" cmd /k "conda activate agent-py311 && cd /d {backend_dir} && python run_server.py"'
        subprocess.run(backend_cmd, shell=True)
        
        # 等待3秒
        print("⏳ 等待后端启动...")
        time.sleep(3)
        
        # 启动前端 (base环境)
        print("🎨 启动前端服务 (端口3000)...")
        frontend_cmd = f'start "前端" cmd /k "conda activate base && cd /d {frontend_dir} && npm run dev -- --port 3000"'
        subprocess.run(frontend_cmd, shell=True)
        
        print("\n✅ 启动完成!")
        print("📡 后端地址: http://localhost:8002")
        print("🎨 前端地址: http://localhost:3000")
        print("\n💡 两个服务将在新窗口中运行，关闭窗口即可停止服务")
        
        input("\n按回车键退出...")
        
    except Exception as e:
        print(f"❌ 启动失败: {e}")
        sys.exit(1)

if __name__ == "__main__":
    main()
